package calculations;

import com.carpark.ejb.Model.TarrifsModel;
import java.util.Date;

/**
 *
 * @author Piotr
 */
public class PassCost {

    public PassCost(){
        
    }
    
    public double countCostOfPass(Date start, Date end, TarrifsModel tarrif){
        long startTime = start.getTime();
        long endTime = end.getTime();
        long passTime = endTime - startTime;
        String durationTime = tarrif.getDurationTime();
        long divisor = divisor(durationTime);
        int totalPart = (int) Math.floor(passTime/divisor);
        int rest = (int) (passTime % divisor);
        if(rest > 0){
            ++totalPart;
        }
        double price = totalPart*tarrif.getRank();
        
        return price;
    }
    
    private long divisor(String durationTime) {
        long divisor = 86400000;
        if(durationTime.equals("Hour")){
            divisor = 3600000;
        }
        if(durationTime.equals("Day")) {
            divisor = 86400000;
        }
        if(durationTime.equals("Week")){
            divisor = 604800000;
        }
        if(durationTime.equals("Two wee")){
            divisor = 1209600000;
        }
        if(durationTime.equals("Month")){
            divisor = 2629744000l;
        }
        return divisor;
    }
    
    
    
}
